
;(function (global){
	// 用户操作地址
	var CGI = {
		MD_COIN_PASSWD 	: window.frontPath + 'user/updateCoinPasswd', // 修改资金密码
		SET_COIN_PASSWD : window.frontPath + 'user/setCoinPasswd' // 修改资金密码
	};
	
	var PASSWD_ERROR = {
			USER_PASSWD 	: {
				NULL : '原始密码不能为空',
				ERROR: '密码长度应在6到16个字符之间'
			},
			NEW_USER_PASSWD  	: {
				NULL  : '新密码不能为空',
				ERROR : '新密码长度应在6到16个字符之间'
			},
			CONFIRM_USER_PASSWD : {
				NULL  : '确认密码不能为空',
				ERROR : '两次输入密码不一致'
			}
		};
		//初始化输入框默认提示组件
		$.placeholder.init();
	
	  
	$.validation.init([{									//新密码
		ele : $('#coin-passwd [name="newCoinPassword"]'),
		checkHandler : function (){
			var _val = $.trim(this.ele.val());
			if(_val == ''){
				return PASSWD_ERROR.NEW_USER_PASSWD.NULL;
			}
			
			if(!$.check.isPwd(_val)){
				return PASSWD_ERROR.NEW_USER_PASSWD.ERROR;
			}
			
			return true;
		}
	},{									//确认密码
		ele : $('#coin-passwd #confirmCoinPassword'),
		checkHandler : function (){
			var _val = $.trim(this.ele.val());
			var _pwd = $.trim($('[name="newCoinPassword"]').val());
			
			if(_val == ''){
				return PASSWD_ERROR.CONFIRM_USER_PASSWD.NULL;
			}
			
			if(_val !== _pwd){
				return PASSWD_ERROR.CONFIRM_USER_PASSWD.ERROR;
			}
			
			return true;
		}
	}],$('#setCoinPasswd'));
	
	
	$.validation.init([{									//设置资金密码
		ele : $('#coin-passwd [name="coinPassword"]'),
		checkHandler : function (){
			var _val = $.trim(this.ele.val());
			if(_val == ''){
				return PASSWD_ERROR.NEW_USER_PASSWD.NULL;
			}
			
			if(!$.check.isPwd(_val)){
				return PASSWD_ERROR.NEW_USER_PASSWD.ERROR;
			}
			
			return true;
		}
	},{									//确认密码
		ele : $('#coin-passwd #confirmCoinPassword'),
		checkHandler : function (){
			var _val = $.trim(this.ele.val());
			var _pwd = $.trim($('[name="coinPassword"]').val());
			
			if(_val == ''){
				return PASSWD_ERROR.CONFIRM_USER_PASSWD.NULL;
			}
			
			if(_val !== _pwd){
				return PASSWD_ERROR.CONFIRM_USER_PASSWD.ERROR;
			}
			
			return true;
		}
	}],$('#setCoinPasswdFrm'));
	
	// 修改资金密码
	$('#setCoidPassWD').click(function (){
		var coinPassword=document.getElementById("coinPassword");
		var newCoinPassword=document.getElementById("newCoinPassword");
		var confirmCoinPassword=document.getElementById("confirmCoinPassword");
		if($.validation.isSuccess($('#setCoinPasswd'))){
			var dataStr = $.substitute('coinPassword={coinPassword}&newCoinPassword={newCoinPassword}&r={curTime}', {
				coinPassword : coinPassword.value,
				newCoinPassword : newCoinPassword.value,
				curTime : new Date().getTime()
			});
			$.ajax({
				url : CGI.MD_COIN_PASSWD,
				method : 'POST',
				data : dataStr,
				success : function(result) {
					//var result =eval("("+data+")");
					if(result.retcode!='0')
					{
						return 	$.alert({
				    		status : 'error',
							basicTitle : result.retmsg
						});
					}
				    $.alert({
			    		status : 'ok',
						basicTitle : result.retmsg
					});  
				    return window.setTimeout(function (){
		    			$.none_alert(function (){
		    				window.location.href = window.frontPath+ 'home#/user/info';
		    			});
		    		},2000);
				}
			});
		}
	});
	
	//设置资金密码
	$('#setCoidPassBtn').click(function (){ 
		var coinPassword=document.getElementById("coinPassword");
		var confirmCoinPassword=document.getElementById("confirmCoinPassword");
		if($.validation.isSuccess($('#setCoinPasswdFrm'))){
			var dataStr = $.substitute('coinPassword={coinPassword}&confirmCoinPassword={confirmCoinPassword}&r={curTime}', {
				coinPassword : coinPassword.value,
				confirmCoinPassword:confirmCoinPassword.value,
				curTime : new Date().getTime()
			});
			$.ajax({
				url : CGI.SET_COIN_PASSWD,
				method : 'POST',
				data : dataStr,
				success : function(result) {
					//var result =eval("("+data+")");
					if(result.retcode!='0')
					{
						return 	$.alert({
				    		status : 'error',
							basicTitle : result.retmsg
						});
					}
				    $.alert({
			    		status : 'ok',
						basicTitle : result.retmsg
					});  
				    window.setTimeout(function (){
		    			$.none_alert(function (){
		    				window.location.href = window.frontPath+ 'home#user/passwd';
		    			});
		    		},2000);
				}
			});
		}
	});


})(window);